﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL;

namespace IPR_TrainExamSys_TY
{
    public partial class FrmLoginNew : Form
    {
        public DialogResult frmLoginResult = DialogResult.No;
        public Model.T_PublicEmployee m_userinfo = new Model.T_PublicEmployee();
        public FrmLoginNew()
        {
            InitializeComponent();
        }

        private void tbUserID_KeyUp(object sender, KeyEventArgs e)
        {
            if (tbUserID.Text.Trim() == "")
                return;
            else
            {
                bool blSearch = false;
                string swhere = " EmployeeId ='" + tbUserID.Text.Trim() + "' ";
               m_userinfo = new T_PublicEmployee().GetModel(swhere);
                if (m_userinfo != null)
                {
                    lbName.Text = m_userinfo.EmployeeName;
                    tbPwd.Focus();
                    tbPwd.SelectAll();
                    blSearch = true;
                }
                if (!blSearch)
                    lbName.Text = "";
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            frmLoginResult = DialogResult.No;
            this.Close();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (tbUserID.Text.Trim() == "")
            {
                MessageBox.Show("请输入用户工号！", "提示");
                tbUserID.Focus();
                tbUserID.SelectAll();
                return;
            }
            else
            {
                try
                {
                    string swhere = " EmployeeId ='" + tbUserID.Text.Trim() + "' and ISNULL( Password,'')='" + tbPwd.Text.Trim() + "'";
                    Model.T_PublicEmployee m_userinfo = new T_PublicEmployee().GetModel(swhere);
                    if (m_userinfo != null)
                    {
                        frmLoginResult = DialogResult.Yes;
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("用户名或密码错误！", "提示");
                        return;
                    }
                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message, "错误");
                }
            }
        }

        private void FrmLoginNew_Load(object sender, EventArgs e)
        {
            tbUserID.Focus();

            
            //string sfinger1="";
            //byte[] b = null;
            //DataSet dsResult = new T_Member().GetList("5", "", "", "", "");
            //if (dsResult != null)
            //    if (dsResult.Tables.Count > 0)
            //        if (dsResult.Tables[0].Rows.Count > 0)
            //        {
            //             b = (byte[])dsResult.Tables[0].Rows[0]["FingerPwd1"];
            //        }
            //if (b != null)
            //{
            //    if (Encoding.Default.GetString(b) == "")
            //    {
            //        pictureBox3.Image = null;
            //        return;
            //    }
            //    System.IO.MemoryStream ms = new System.IO.MemoryStream(b);
            //    System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
            //    pictureBox3.Image = img;
            //}
        }
    }
}
